package jp.nyatla.tap;

import java.io.Serializable;

import twitter4j.ProfileImage;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.http.*;



public class TwitterSessionData implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2658828247251953078L;
	//基本パラメタ
	public int c;
	public int state;
	public int mode;
	public int client_type;		//クライアントタイプ
	//認証情報
	public String access_token;
	public String access_token_secret;
	public String request_token;
	public String request_token_secret;

	//SESSION情報
	public String pf_img_url;
	public String pf_sname;
	public int user_id;
	public long last_status_id;	//読出し終了位置
	
	/**
	 * ツイッターセッションの状態値
	 */
	public static final int ST_SIGNOUT = 0;
	public static final int ST_SIGNIN = 1;
	public static final int ST_PREV = 2;	
	/**
	 * モード値
	 */
	public static final int MODE_NORMAL = 0;
	public static final int MODE_BATTLE = 1;
	
	public TwitterSessionData(String i_user_agent)
	{
		this.initSignOut();
		this.client_type=NtgUtil.getClientType(i_user_agent);
	}
	public void initSignOut()
	{
		this.mode  =MODE_NORMAL;
		this.state =ST_SIGNOUT;
	}
	public void initSignin(Twitter i_twitter) throws TwitterException
	{
		AccessToken ac=i_twitter.getOAuthAccessToken(new RequestToken(this.request_token,this.request_token_secret));
		this.state =ST_SIGNIN;
		this.access_token=ac.getToken();
		this.access_token_secret=ac.getTokenSecret();
		
		//ここから編集。
		this.last_status_id=0;
		this.user_id=i_twitter.getId();
		this.pf_sname=i_twitter.getScreenName();
		this.pf_img_url=i_twitter.getProfileImage(this.pf_sname,ProfileImage.NORMAL).getURL();
	}
	public void initPrev(RequestToken i_request)
	{
		this.state =ST_PREV;
		this.request_token = i_request.getToken();
		this.request_token_secret = i_request.getTokenSecret();
	}

	public String dumpStr()
	{
		return
		"c:"+c+"\n"+
		"state:"+state+"\n"+
		"mode:"+mode+"\n"+
		
		"access_token:"+access_token+"\n"+
		"access_token_secret:*****\n"+
		"request_token:"+request_token+"\n"+
		"request_token_secret:*****\n"+
		
		"pf_img_url:"+pf_img_url+"\n"+
		"pf_sname:"+pf_sname+"\n"+
		"user_id:"+user_id+"\n"+
		"last_status_id:"+last_status_id+"\n"+
		"client_type:"+client_type+"\n";
	}

}